<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>留言板</title>
	</head>
	<body>
		<table border="0" cellspacing="0" cellpadding="4">
			<tr>
				<td>姓名:</td>
				<td colspan="4"><input type="text" name="" id="in1" value="" /></td>
			</tr>
			<tr>
				<td>留言：</td>
				<td colspan="4"><textarea id="text1" rows="5" cols="35"></textarea></td>
			</tr>
			<tr>
				<td></td>
				<td><button onclick="fun1()">重置</button></td>
				<td><button onclick="fun2()">留言</button></td>
				<td></td>
			</tr>
		</table>
		<hr>
		<textarea style="resize: none;" id="text2" cols="80" rows="11" disabled="disabled"></textarea>
	</body>
	<script>
		var fun1 = function() {
			if (confirm("是否确认清空？")) {
				document.getElementById("in1").value = "";
				document.getElementById("text1").value = "";
			} else {
				return false;
			}
		}


		var i = 0;
		var k = 0;
		var arrays1 = [];
		var arrays2 = [];
		var fun2 = function() {

			if (document.getElementById("in1").value == "" || document.getElementById("text1").value == "") {
				alert("存在必填项为空！！！");
				return false;
			}

			var str1 = document.getElementById("in1").value;
			var str2 = document.getElementById("text1").value;
			var time = new Date();
			var hour = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
			var min = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
			var scend = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
			var date = time.getHours() < 12 ? "在上午" : "在下午"
			var result = "[" + str1 + "]" + date + hour + ":" + min + ":" + scend + "说:" + str2;
				k = arrays1.length - 1;
				for (; k >= 0; k--) {
					arrays1[k + 1] = arrays1[k];
				}
				arrays1[0] = result;
				if(arrays1.length>=10){
					for(var m=0;m<10;m++){
						arrays2[m]=arrays1[m];
					}
					
					var srt = '';
					for (var j = 0; j < arrays2.length; j++) {
						srt = srt + arrays2[j].toString() + '\n';
					}
					var context = document.getElementById("text2");
					context.value = srt;
				}else{
					var srt = '';
					for (var j = 0; j < arrays1.length; j++) {
						srt = srt + arrays1[j].toString() + '\n';
					}
					var context = document.getElementById("text2");
					context.value = srt;
				}
				
			
		}
	</script>
</html>
